home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 22.7 KB | 733 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UMailerView.cp
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
-
- #if qPowerTalk
-
- #ifndef __UMAILERVIEW__
- #include "UMailerView.h"
- #endif
-
- // MacApp
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UMAILER__
- #include "UMailer.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMAILABLE__
- #include "UMailable.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- // #endif
-
- // Toolbox
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __OCEERRORS__
- #include <OCEErrors.h>
- #endif
-
- #ifndef __OCESTANDARDDIRECTORY__
- #include <OCEStandardDirectory.h>
- #endif
-
- //========================================================================================
- // GLOBAL Functions
- //========================================================================================
-
- PrepareMailerForDrawingUPP gMacAppPrepareMailerForDrawingProc;
- FrontWindowUPP gFrontWindowUPP;
-
- //----------------------------------------------------------------------------------------
- // Prototypes for local functions
- //----------------------------------------------------------------------------------------
-
- pascal void MacAppPrepareMailerForDrawingProc(WindowRef window, long clientData);
- pascal WindowRef MyFrontWindowProc(long data);
-
- //----------------------------------------------------------------------------------------
- // MacAppPrepareMailerForDrawingProc
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- pascal void MacAppPrepareMailerForDrawingProc(WindowRef /* window */,
- long clientData)
- {
- TView* theMailerView = (TView *)clientData;
- theMailerView->Focus();
- }
-
- //----------------------------------------------------------------------------------------
- // MyFrontWindowProc
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- pascal WindowRef MyFrontWindowProc(long /* clientData */)
- {
- // PowerTalk 1.1 is supposed to set A5 but doesn't.
- #if qSegments
- // Set and restore A5 for compatibility with AOCE
- long A5RegisterOnEntry = SetCurrentA5();
- #endif
- WindowRef frontWindow = NULL;
- {
- frontWindow = TWindow::MAFrontWindow();
- }
- #if qSegments
- SetA5(A5RegisterOnEntry);
- #endif
- return frontWindow;
- }
-
- //----------------------------------------------------------------------------------------
- // InitUMailerView
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
-
- void InitUMailerView()
- {
- if (!HasAOCEToolBox())
- {
- #if qDebug
- ProgramBreak("InitUMailerView called but AOCE isn't present.");
- #endif
- return;
- }
-
- FailNIL(gMacAppPrepareMailerForDrawingProc = NewPrepareMailerForDrawingProc(&MacAppPrepareMailerForDrawingProc));
- FailNIL(gFrontWindowUPP = NewFrontWindowProc(&MyFrontWindowProc));
- }
-
- //========================================================================================
- // CLASS TMailerView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment AOCEMailerRes
- MA_DEFINE_CLASS_M1(TMailerView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TMailerView::TMailerView
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TMailerView::TMailerView()
- : fLetter(NULL),
- fLastTargetField(kSMPRegarding),
- fMailerExpanded(FALSE),
- fMailerClosed(FALSE)
- {
- fHandlesCursor = FALSE;
- fLetsSubViewsHandleCursor = FALSE;
- fWantsToBeTarget = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TMailerView::~TMailerView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::IMailerView
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::IMailerView(TLetter* itsLetter,
- TView* itsSuperView,
- Boolean initiallyExpanded)
- {
- // Initializes a mailer view but does not actually create a mailer.
-
- FailNonObject(itsLetter);
- TDocument* itsDocument = itsLetter->fDocument;
-
- fLetter = itsLetter;
- fIdentifier = kMailerViewID;
-
- CPoint dimensions = TMailerView::GetDimensions(initiallyExpanded);
-
- // size width up to size of superview
- if (itsSuperView->fSize.h > dimensions.h)
- dimensions.h = itsSuperView->fSize.h;
-
- VPoint theSize(dimensions);
- this->IView(itsDocument, itsSuperView, gZeroVPt, theSize, sizeSuperView, sizeVariable);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::OpenNewMailer : Creates a new mailer in the view.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::OpenNewMailer(Boolean initiallyExpanded,
- Boolean canContract)
- {
- GrafPtr thePort = this->GetGrafPort();
- long clientData = (long)this;
-
- FailOSErr(SMPNewMailer(thePort, gZeroPt, canContract, initiallyExpanded, 0,
- gMacAppPrepareMailerForDrawingProc, clientData));
- fMailerExpanded = initiallyExpanded;
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::OpenOldMailer : Creates a mailer in the view for an existing letter.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::OpenOldMailer(LetterDescriptor theDesc,
- Boolean initiallyExpanded,
- Boolean canContract)
- {
- GrafPtr thePort = this->GetGrafPort();
- long clientData = (long)this;
- AuthIdentity localIdentity;
-
- // Don't allow user interaction when getting the local identity. It should
- // be impossible to get here without a valid id being available.
- if (gMailing->GetAOCEIdentity(localIdentity, FALSE) == noErr)
- {
- FailOSErr(SMPOpenLetter(&theDesc, thePort, gZeroPt, canContract,
- initiallyExpanded, gMacAppPrepareMailerForDrawingProc, clientData));
- fMailerExpanded = initiallyExpanded;
- }
- #if qDebug
- else
- {
- ProgramBreak("TMailerView::OpenOldMailer unexpectedly couldn't get local identity.");
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::OpenReplyMailer : Creates a mailer in the view in reply to an existing
- // letter.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::OpenReplyMailer(WindowRef theReplyToWindow,
- Boolean replyToAll,
- Boolean initiallyExpanded,
- Boolean canContract)
- {
- GrafPtr thePort = this->GetGrafPort();
- CPoint upperLeft(0, 0);
- long clientData = (long)this;
- AuthIdentity localIdentity;
-
- // Don't allow user interaction when getting the local identity. It should
- // be impossible to get here without a valid id being available.
- if (gMailing->GetAOCEIdentity(localIdentity, FALSE) == noErr)
- {
- FailOSErr(SMPMailerReply((WindowPtr)theReplyToWindow, thePort, replyToAll, upperLeft,
- canContract, initiallyExpanded, localIdentity, gMacAppPrepareMailerForDrawingProc, clientData));
- fMailerExpanded = initiallyExpanded;
- }
- #if qDebug
- else
- {
- ProgramBreak("TMailerView::OpenReplyMailer unexpectedly couldn't get local identity.");
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::Activate
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::Activate(Boolean entering)
- {
- // Feed the mail package an activate event.
- EventRecord theEvent;
- BlockSet((Ptr)&theEvent, sizeof(theEvent), 0);
- theEvent.what = activateEvt;
- theEvent.message = (long)this->GetWindow()->fWMgrWindow;
- theEvent.modifiers = entering;
- theEvent.when = TickCount();
- OSErr err = 0;
- SMPMailerResult whatHappened = 0;
- err = SMPMailerEvent(&theEvent, &whatHappened, gFrontWindowUPP, (long)this);
- Inherited::Activate(entering);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::Close
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::Close()
- {
- {
- WindowRef theWindow = this->GetWindow()->fWMgrWindow;
-
- if (fLetter->fLetterTabber) // Remove the tabber
- {
- TWindow *mailerWindow = fLetter->GetMailerWindow();
- mailerWindow->RemoveBehavior(fLetter->fLetterTabber);
- fLetter->fLetterTabber = (TLetterTabber*)FreeIfObject(fLetter->fLetterTabber);
- }
-
- //We should never fail here - see SMPPrepareToClose in
- //TMailableDocument::Close()
-
- FailOSErr(SMPDisposeMailer((WindowPtr)theWindow, NULL));
- fMailerClosed = TRUE;
- }
- Inherited::Close();
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::Draw : Tells the mail package to draw the mailer.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::Draw(const VRect& area)
- {
- Inherited::Draw(area);
- FailOSErr(SMPDrawMailer(this->GetGrafPort()));
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::BecameTarget : Inform the mail package that the mailer view has been
- // targeted.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::BecameTarget()
- {
- SMPMailerState theMailerState;
- WindowPtr theWindowPtr = (WindowPtr)this->GetWindow()->fWMgrWindow;
-
- Inherited::BecameTarget();
-
- FailOSErr(SMPGetMailerState(theWindowPtr, &theMailerState));
-
- if (!theMailerState.isTarget && this->Focus())
- FailOSErr(SMPBecomeTarget(theWindowPtr, TRUE, this->fLastTargetField));
-
- gClipboardMgr->AboutToLoseControl(TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::ResignedTarget : Inform the mail package that the mailer view is no
- // longer the target.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::ResignedTarget()
- {
- Inherited::ResignedTarget();
- if (!fMailerClosed && this->Focus())
- {
- WindowPtr theWindowPtr = (WindowPtr)this->GetWindow()->fWMgrWindow;
- SMPMailerState theMailerState;
-
- FailOSErr(SMPGetMailerState(theWindowPtr, &theMailerState));
-
- if (theMailerState.isTarget)
- {
- this->fWantsToBeTarget = FALSE;
- FailOSErr(SMPBecomeTarget(theWindowPtr, FALSE, 0));
- this->fLastTargetField = theMailerState.targetComponent;
- }
- }
- gClipboardMgr->CheckDeskScrap();
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::ExpandMailer : Expands the mailer to its full size.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::ExpandMailer()
- {
- if (this->Focus())
- {
- VRect oldFrame(this->GetFrame());
-
- CPoint dimensions = TMailerView::GetDimensions(kExpanded);
- VRect newFrame(0, 0, oldFrame.right, dimensions.v);
- this->SetFrame(newFrame, kDontInvalidate);
-
- OSErr err = SMPExpandOrContract(this->GetGrafPort(), kExpanded);
-
- // Move other views down
- long vOffset = newFrame.GetLength(vSel) - oldFrame.GetLength(vSel);
-
- this->fMailerExpanded = TRUE;
- fLetter->MakeRoomForMailer(vOffset, kRedraw);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::ContractMailer : Shrinks the mailer to its contracted size.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::ContractMailer()
- {
- if (this->Focus())
- {
- VRect oldFrame(this->GetFrame());
-
- CPoint dimensions = TMailerView::GetDimensions(kContracted);
- VRect newFrame(0, 0, oldFrame.right, dimensions.v);
- this->SetFrame(newFrame, kInvalidate);
-
- OSErr err = SMPExpandOrContract(this->GetGrafPort(), kContracted);
-
- // Move other views up
- long vOffset = newFrame.GetLength(vSel) - oldFrame.GetLength(vSel);
-
- this->fMailerExpanded = FALSE;
- fLetter->MakeRoomForMailer(vOffset, kRedraw);
-
- if (this->IsTarget() && this->ResignTarget())
- {
- this->fWantsToBeTarget = FALSE;
- TWindow *theWindow = this->GetWindow();
- if (theWindow && theWindow->GetWindowTarget() == this)
- theWindow->SetWindowTarget(NULL);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::GetDimensions : returns the size of the mailer in its contracted or
- // expanded state.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- CPoint TMailerView::GetDimensions(Boolean expanded)
- {
- CPoint dimensions;
- short contHeight;
- short expHeight;
- FailOSErr(SMPGetDimensions(&dimensions.h, &contHeight, &expHeight));
-
- dimensions.v = expanded ? expHeight : contHeight;
- return dimensions;
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::DoSetupMenus : Handles the Edit Menu Items based on status of the mailer.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::DoSetupMenus()
- {
- Inherited::DoSetupMenus();
- WindowRef theWindow = this->GetWindow()->fWMgrWindow;
- SMPMailerState theMailerState;
- FailOSErr(SMPGetMailerState((WindowPtr)theWindow, &theMailerState));
- Enable(cForward, theMailerState.hasBeenReceived);
- Enable(cReply, theMailerState.hasBeenReceived);
- if (fMailerExpanded)
- {
- Boolean isTarget = theMailerState.isTarget;
- Enable(cClear, isTarget & theMailerState.canClear);
- Enable(cCopy, isTarget & theMailerState.canCopy);
- Enable(cPaste, isTarget & theMailerState.canPaste);
- Enable(cSelectAll, isTarget & theMailerState.canSelectAll);
- Enable(cCut, isTarget & theMailerState.canCut);
- Boolean canUndo = theMailerState.undoState == kSMPMailerUndo;
- Enable(cUndo, isTarget & canUndo);
- if (canUndo)
- {
- CStr255 newCmdName = theMailerState.undoWhat;
- SetCommandName(cUndo, newCmdName);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::DoMenuCommand : Handles the edit menu items for the mailer.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::DoMenuCommand(CommandNumber aCommandNumber)
- {
- const SMPEditCommand kSMPNoCommand = 65535;
- SMPEditCommand command = kSMPNoCommand;
- SMPMailerResult whatHappened = 0;
- if (fMailerExpanded)
- {
- switch (aCommandNumber)
- {
- case cUndo:
- command = kSMPUndoCommand;
- break;
- case cCut:
- command = kSMPCutCommand;
- break;
- case cCopy:
- command = kSMPCopyCommand;
- break;
- case cPaste:
- command = kSMPPasteCommand;
- break;
- case cClear:
- command = kSMPClearCommand;
- break;
- case cSelectAll:
- command = kSMPSelectAllCommand;
- break;
- }
- }
- WindowRef theWindow = this->GetWindow()->fWMgrWindow;
- if (command != kSMPNoCommand)
- {
- FailOSErr(SMPMailerEditCommand((WindowPtr)theWindow, command, &whatHappened));
- if (whatHappened & kSMPAppMustHandleEventBit)
- Inherited::DoMenuCommand(aCommandNumber);
- }
- else
- Inherited::DoMenuCommand(aCommandNumber);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::DoMailerEvent : Handles mouse and keyboard events for the mailer.
- // Other events are handled in MMailing::DoMailerEvent.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::DoMailerEvent(TToolboxEvent* event)
- {
- TWindow *theWindow = this->GetWindow();
- EventRecord theEvent = event->fEventRecord;
- SMPMailerResult whatHappened = 0;
-
- OSErr eventErr = SMPMailerEvent(&theEvent, &whatHappened, gFrontWindowUPP, (long)this);
- if (eventErr != kSMPAddressAlreadyInList) // ignore duplicate address error
- {
- FailOSErr(eventErr);
-
- if (whatHappened & kSMPExpandedMask)
- this->ExpandMailer();
- if (whatHappened & kSMPContractedMask)
- this->ContractMailer();
- if ((whatHappened & kSMPCreateCopyWindowMask) || (whatHappened & kSMPDisposeCopyWindowMask))
- InvalidateMenuBar();
- }
-
- if (!this->IsTarget() && (whatHappened & kSMPMailerBecomesTargetMask))
- {
- this->fWantsToBeTarget = TRUE;
- gDispatcher->SetTarget(this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::DoKeyEvent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::DoKeyEvent(TToolboxEvent* event)
- {
- Inherited::DoKeyEvent(event);
- this->DoMailerEvent(event);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::DoKeyUp
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::DoKeyUp(TToolboxEvent* event)
- {
- this->DoMailerEvent(event);
- Inherited::DoKeyUp(event);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::DoMouseCommand
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis)
- {
- this->DoMailerEvent(event);
- Inherited::DoMouseCommand(theMouse, event, hysteresis);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::DoMouseUp
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailerView::DoMouseUp(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis)
- {
- this->DoMailerEvent(event);
- Inherited::DoMouseUp(theMouse, event, hysteresis);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::InvalidateFrameDifference:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TMailerView::InvalidateFrameDifference(const VRect& oldFrame,
- const VRect& newFrame)
- {
- // Override to adjust frame for extra pixel that PowerTalk draws for 3d
- // hiliting
- VRect adjustedFrame = oldFrame;
- adjustedFrame.right -= 1;
- Inherited::InvalidateFrameDifference(adjustedFrame, newFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailerView::WantsToBeTarget
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- Boolean TMailerView::WantsToBeTarget() // Override
- {
- return (fWantsToBeTarget && fMailerExpanded);
- } //TMailerView::WantsToBeTarget
-
- //----------------------------------------------------------------------------------------
- // TMailerView::WantsToBeTabTarget
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- Boolean TMailerView::WantsToBeTabTarget() // Override
- {
- return fMailerExpanded;
- } //TMailerView::WantsToBeTabTarget
-
- //========================================================================================
- // CLASS TLetterTabber
- //========================================================================================
- #undef Inherited
- #define Inherited TViewTabber
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TLetterTabber, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TLetterTabber::TLetterTabber: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TLetterTabber::TLetterTabber()
- : TViewTabber(),
- fLetter(NULL)
- {
- } // TLetterTabber::TLetterTabber
-
- //----------------------------------------------------------------------------------------
- // TLetterTabber destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TLetterTabber::~TLetterTabber()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TLetterTabber::IMailWindowTabber:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TLetterTabber::ILetterTabber(Boolean recursive,
- TLetter *itsLetter)
- {
- fLetter = itsLetter;
- this->IViewTabber(recursive);
- } // TViewTabber::IMailWindowTabber
-
- //----------------------------------------------------------------------------------------
- // TLetterTabber::FindSubViewTargets:
- //----------------------------------------------------------------------------------------
- #pragma segment MATabBehaviorRes
-
- void TLetterTabber::FindSubViewTargets(TView* parent,
- Boolean tabBackward)
- {
- TMailerView *mailerView = fLetter->GetMailerView();
- Boolean mailerIsTarget = mailerView->IsTarget();
- Boolean optionIsDown = IsOptionKeyDown();
-
- CSubViewIterator iter(parent,!tabBackward);
-
- for (TView* aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- {
- Boolean canBeTarget;
-
- if (aView == mailerView)
- canBeTarget = aView->IsEnabled() && aView->IsShown() && mailerView->WantsToBeTabTarget();
- else
- canBeTarget = aView->IsEnabled() && aView->IsShown() && aView->WantsToBeTarget();
-
- if (canBeTarget && (optionIsDown != (mailerIsTarget != (aView == mailerView))))
- canBeTarget = FALSE;
-
- if ((fFirst == NULL) && canBeTarget)
- fFirst = aView;
-
- if (aView->IsTarget())
- fFoundCurrent = TRUE;
- else if (fFoundCurrent && (fNext == NULL) && canBeTarget)
- {
- fNext = aView;
- return;
- }
-
- if (fRecursive)
- this->FindSubViewTargets(aView,tabBackward);
- }
- } // TLetterTabber::FindSubViewTargets
-
- #endif // qPowerTalk
-
- //----------------------------------------------------------------------------------------
- // End of UMailerView.cp
-
- #pragma segment Inline
-